package org.pro.core.social.qq.config;

import org.pro.core.properties.QQProperties;
import org.pro.core.properties.SecurityProperties;
import org.pro.core.social.qq.connect.QQConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.social.config.annotation.ConnectionFactoryConfigurer;
import org.springframework.social.config.annotation.SocialConfigurerAdapter;
/**
 * 配置数据源 
 * @author luoqiz
 *
 */
import org.springframework.social.security.SpringSocialConfigurer;

@Configuration
public class QQSocialConfig extends SocialConfigurerAdapter {

	@Autowired
	private SecurityProperties securityProperties;

	
	@Override
	public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
		QQProperties qq = securityProperties.getSocialProperties().getQqProperties();
		QQConnectionFactory qqConnectionFactory = new QQConnectionFactory(qq.getProviderId(), qq.getAppId(),
				qq.getAppSecret());
		cfConfig.addConnectionFactory(qqConnectionFactory);
	}

	@Bean
	public SpringSocialConfigurer qqSocialConfig() {
		String url = securityProperties.getSocialProperties().getFilterProcessesUrl();
		QQSpringSocialConfigurer qqSpringSocialConfigurer = new QQSpringSocialConfigurer(url);
		qqSpringSocialConfigurer.signupUrl(securityProperties.getBrowser().getSignUpUrl());
		return qqSpringSocialConfigurer;
		// return new SpringSocialConfigurer();
	}
}
